package com.ddone.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ddone.bean.User;
import com.ddone.bean.vo.ResultCode;
import com.ddone.bean.vo.ResultVo;
import com.ddone.service.UserService;
import io.swagger.annotations.*;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ddone
 * @date 2024/3/25-22:36
 */
@Api(tags = "用户管理页面")
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    // @GetMapping
    // public List<User> list() {
    //     return userService.list();
    // }

    @ApiOperation("获取用户分页数据")
    @GetMapping("page/{pageNo}/{pageSize}")
    public List<User> page(@PathVariable("pageNo") Long pageNo, @PathVariable("pageSize") Long pageSize){

            Page<User> userPage = new Page<>(pageNo, pageSize);
            LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<User>().eq(User::getGender, "女");
        return userService.page(userPage,queryWrapper).getRecords();
    }
    @ApiOperation("用统一响应进行返回")
    @GetMapping("/vo")
    public ResultVo listVo() {
        return new ResultVo(userService.page(new Page<User>(10,3)));
    }

    @PostMapping
    @ApiOperation("用户登录")
    @ApiImplicitParams({
            @ApiImplicitParam(name="username",value = "用户名",paramType = "body",required = true),
            @ApiImplicitParam(name="phone",value = "手机号",paramType = "body",required = true),
    })
    public ResultVo login(@ApiParam("登录的用户信息") User user ){
        System.out.println(user);
        return new ResultVo(ResultCode.SUCCESS);
    }
}
